package com.yzdmw.toutiao;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.yzdmw.toutiao.information_edit.edit_page;

//import com.yzdmw.toutiao.wheeldisk.WheeldiskFragment;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
        setSlidingMenu(this);
        getSupportActionBar().hide();
        requestPermissions();
    }

    private SlidingMenu menu;
    private void setSlidingMenu(Activity activity) {
        menu=new SlidingMenu(activity);
        menu.setMode(SlidingMenu.LEFT_RIGHT);
        menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        menu.setTouchModeBehind(SlidingMenu.TOUCHMODE_FULLSCREEN);
        menu.setFadeDegree(0.55f);
        menu.setMenu(R.layout.left_page);
        menu.setSecondaryMenu(R.layout.right_page);
        menu.setBehindScrollScale(1.0f);
        menu.setRightBehindOffsetRes(R.dimen.menu_offset);//设置相对屏幕的偏移量
        menu.attachToActivity(activity,SlidingMenu.SLIDING_CONTENT);
    }

    public void disableSlidingMenu() {
        menu.setSlidingEnabled(false);
    }

    public void enableSlidingMenu() {
        menu.setSlidingEnabled(true);
    }

    private void requestPermissions() {
        // TODO: 有用到权限的请务必先请求，此处为预申请，也可以在使用时才申请
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(
                    this,
                    new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},
                    1);
        }
    }
}